package thisgame.model;
import java.awt.*;
import java.util.*;

/**
 * 캐릭터를 나타내는 클래스.
 * 
 * @author isurit
 *
 */
public class Character implements Colliding, Collidable {
	private String name;
	private Position position;
	private Vector2D velocity;
	private int str;
	private int dex;
	private int luk;
	private Map<Direction,Image> chaImages;
	private Direction key;

	public Character() {
		this("unknown", 0, 0);
	}

	public Character(String str, int x, int y) {
		position = new Position(x, y);
		name = str;
		chaLoading();
		System.out.println(name + " created");
	}

	public void chaLoading() {
		Toolkit tk = Toolkit.getDefaultToolkit();
		chaImages = new HashMap<Direction, Image>();
		chaImages.put(Direction.UP, tk.getImage("uCha.gif"));
		chaImages.put(Direction.DOWN, tk.getImage("dCha.gif"));
		chaImages.put(Direction.RIGHT, tk.getImage("rCha.gif"));
		chaImages.put(Direction.LEFT, tk.getImage("lCha.gif"));
		key = Direction.DOWN;
	}

	public void move(Direction key) {
		this.key = key;
		switch (key) {
		case UP:
			position.add(0, -1);
			break;
		case RIGHT:
			position.add(1, 0);
			break;
		case DOWN:
			position.add(0, 1);
			break;
		case LEFT:
			position.add(-1, 0);
			break;
		}
	}

	public void paintTo(Graphics g, Point pos,
						java.awt.image.ImageObserver observer) {
		g.drawImage(chaImages.get(key), pos.x, pos.y, 40, 40, observer);
	}

	public String getName() {
		return name;
	}

	public Position getPosition() {
		return position;
	}
	
	public void setPosition(Position newPos) {
		position = newPos;
	}
	
	@Override
	public boolean isCollidingAgainst(Collidable other) {
		return other.isCollidedWith(this.getPosition());
	}
	
	@Override
	public boolean isCollidedWith(Position pos) {
		return getPosition().equals(pos);
	}
	
	@Override
	public boolean isCollidedWith(Collection<Position> positions) {
		for (Position pos : positions) {
			if (getPosition().equals(pos)) return true;
		}
		return false;
	}
}
